package crack3d;

import java.util.ArrayList;

import fem2.AbstractStructuralCrackDemo;
import fem2.Constraint;
import fem2.MaterialModel;
import fem2.Mesh;
import fem2.MeshGenerator;
import fem2.MeshUtilities;
import fem2.Model;
import fem2.Node;
import fem2.ParallelAssembler;
import fem2.enu.State;
import fem2.material.StVenantKirchhoffMM;
import fem2.observer.StressObserver;
import fem2.observer.TimeStepObserver;
import fem2.pre_and_post.GidMeshGenerator;
import fem2.strategies.Strategy;

public abstract class AbstractLshape3dUsingSDAElement extends AbstractStructuralCrackDemo {

	public AbstractLshape3dUsingSDAElement() {
		projectDir = "/home/hbui/kratos_janosch";
		projectName = "Lshape3d.gid";
	}

	@Override
	public Mesh createMesh() {
		String fn = projectDir + '/' + projectName + '/' + meshFileName;
		MeshGenerator mg = new GidMeshGenerator(fn);
		Mesh mesh = mg.getMesh(3);
		return mesh;
	}

	@Override
	public Model createConditions(Model m) {
		Mesh mesh = m.getMesh();
		Constraint c1 = new Constraint(false, false, false);
		Constraint c2 = new Constraint(true, false, true);
		double du = -0.01;
		c2.setValue(1, du);
		ArrayList<Node> top = MeshUtilities.seekNodesOnSurface(mesh, 0, 1, 0, -1000);
		ArrayList<Node> edge = MeshUtilities.seekNodesOnLine(mesh, 1000, 500, 0, 0, 0, 1);
		mesh.setConstraint(c1, top);
		mesh.setConstraint(c2, edge);
		return m;
	}

	@Override
	public MaterialModel createMaterial(Model m) {
		double E = 25850;
		double nu = 0.18;
		double t = 1.0;
		State ss = State.THREE_DIMENSIONAL;
		MaterialModel mm = new StVenantKirchhoffMM(E, nu, t, 0, ss);
		return mm;
	}

	@Override
	public void addObservers(Model m, Strategy s, TimeStepObserver o) {
		super.addObservers(m, s, o);

		s.addObserver(new StressObserver(m));
	}

	@Override
	public Model createModel() {
		Model m = super.createModel();
		m.setAssembler(new ParallelAssembler(m, 4));

		return m;
	}
}
